import * as api from '@/api/user'

const state = {
  isAdmin: false
}

const mutations = {
  SET_PERMISSION(state, newValue) {
    state.isAdmin = newValue
  }
}

const actions = {
  async updatePermission({ commit }) {
    const res = await api.getProfile()
    commit('SET_PERMISSION', res.username === '管理员') // to fix
    return res.username === '管理员'
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
